// createBusinessRecords.js

export const createNewBusiness = (id, businessType) => ({
    id: id,
    businessType: businessType,
    startPort: '',
    endPort: '',
    triangleTrade: '',
    transitPort: '',
    transportMode: '',
    currency: '',
    carrier: '',
    carrierCode: '',
    uld: '',
    containerULD: '',
    containerGrade: '',
    serviceLiver: '',
    carrierLevel: '',
    product: '',
    commLocal: '',
    controlCustomer: '',
    shipper: '',
    consignee: '',
    unit: '',
    transportTime: '',
    frequency: '',
    frequencyUnit: '',
    startDate: '',
    expiryDate: '',
    customerContractNo: '',
    contractLink: '',
    contractNo: '',
    publish: false,
    vehicle: '',
    portOfLoading: '',
    portOfDischarge: '',
    postcode: '',
    feeTable: [createNewFeeRecord(id)]
});

export const createNewFeeRecord = (parentId) => {
    const feeId = Date.now().toString();
    return {
        id: feeId,
        parentId,
        costCode: '',
        description: '',
        localDescription: '',
        unit: '',
        tableFormula: '',
        condition: '',
        rateDescription: '',
        tableType: '',
        minAmount: '',
        actualWeightVolume: '',
        unitQuantity: '',
        workingType: '',
        containerType: '',
        calculator: {
            id: `calc-${feeId}`,
            type: 'UNT', // 默认使用单位计算器
            data: createCalculatorData('UNT'),
            parentId: parentId,
            feeId: feeId
        }
    };
};

export const createCalculatorData = (type) => {
    switch (type) {
        case 'UNT':
            return {
                unitPrice: 0,
                agentRate: false,
                unitPriceValue: 0
            };
        // 在这里可以添加其他计算器类型的初始数据结构
        default:
            return {};
    }
};

export const isRowEmpty = (row) => {
    if (!row) return true;
    const fieldsToIgnore = ['id', 'parentId'];
    return Object.entries(row).every(([key, value]) => {
        if (fieldsToIgnore.includes(key)) return true;
        return value === '' || value === null || value === undefined ||
            (typeof value === 'object' && Object.keys(value).length === 0);
    });
};
